<?php

namespace App\Admin\Controllers;

use App\Http\Controllers\BaseController;
use App\Models\CashOrder;
use App\Models\GoodOrder;
use App\Models\ServiceOrder;
use Dcat\Admin\Layout\Column;
use Dcat\Admin\Layout\Content;
use Dcat\Admin\Layout\Row;
use Dcat\Admin\Widgets\Card;
use Illuminate\Support\Facades\Auth;


class HomeController extends BaseController
{
    public function index(Content $content)
    {

        admin_require_assets(['@moment', '@bootstrap-datetimepicker','@vue-render']);
        return $content
            ->header('控制台')
            ->body(function (Row $row) {
                $row->column(12, function (Column $column) {
                    $admin = Auth::guard('admin');
                    $user = $admin->user();
                    $weeks = ['星期日','星期一','星期二','星期三','星期四','星期五','星期六'];
                    $props = [
                        'user'=>['name'=>$user['name'],'username'=>$user['username']],
                        'date'=>date("Y年m月d日")." ".$weeks[date("w")],
                        'times'=>date("H:i:s"),'weeks'=>$weeks
                    ];
                    $card = Card::make("欢迎管理员",view('admin.home.index',$props));
                    $column->row($card);
                    $data = [
                        'count1'=>ServiceOrder::query()->where("status",0)->where("is_apply",0)->where("shop_id",0)->where("worker_id",0)->count(),
                        'count2'=>ServiceOrder::query()->where("status",0)->where("is_apply",0)->where("worker_id",">",0)->count(),
                        'count3'=>GoodOrder::query()->where("state",1)->where("is_apply",0)->count(),
                        'count4'=>GoodOrder::query()->where("state",2)->where("is_apply",0)->count(),
                        'count5'=>GoodOrder::query()->where("state","<",5)->where("is_apply",1)->count(),
                        'count6'=>CashOrder::query()->where("status",0)->count(),
                    ];
                    $data['num'] = array_sum($data);
                    $card = Card::make("待办事项",view('admin.home.wait',$data));
                    $column->row($card);
                });
            });
    }
}
